package mx.com.crowdgine.game;

import javax.media.opengl.GLAutoDrawable;

import com.jme3.input.MouseInput;

import mx.com.crowdgine.app.JoglApplication;
import mx.com.crowdgine.assetloader.Asset;
import mx.com.crowdgine.assetloader.OBJModelAsset;
import mx.com.crowdgine.camera.JoglCamera;
import mx.com.crowdgine.crowds.CrowdSystem;
import mx.com.crowdgine.display.animation.glsl.GLSLAnimation;
import mx.com.crowdgine.entity.Entity;
import mx.com.crowdgine.entity.geometry.Cube;
import mx.com.crowdgine.entity.geometry.Plane;
import mx.com.crowdgine.particlesystem.ParticleSystem;
import mx.com.crowdgine.util.math.Vector3f;

public class GameTest extends JoglApplication {
	
	public Entity cube;
	public Entity plane;
	public Asset mrT;
	
	public ParticleSystem particleSystem;
	public CrowdSystem simpleCrowd;
	
	public float x;
	public float time;
	
	public GameTest(String frameName, int width, int height){
		super(frameName, width, height);
	}
	
	
	public static void main(String [] args){
		GameTest game= new GameTest("Joyful GameTest",640,480);
		game.start();
	}
	
	@Override
	public void initialize(){
		super.initialize();
		addAndSetCamera(new JoglCamera());
		x=0.1f;
		time=0;
		cube = new Cube(x);
		plane = new Plane(4.0f, new Vector3f(0.2f, 0.4f, 0.8f));
		plane.translate(new Vector3f(5,0,0));
		addEntity(cube);
		addEntity(plane);
		
		mrT = new OBJModelAsset();
		mrT.setAnimation(new GLSLAnimation("Assets/shaders/wobbleVertex.glsl", "Assets/shaders/wobbleFragment.glsl"));
		// to see current work directory uncomment the following line
		// System.out.println(new File(".").getAbsolutePath());
		mrT.setAssetName("Assets/Models/mrT");
		addAsset(mrT);
		
	}
	
	@Override
	public void init(GLAutoDrawable drawable){
		super.init(drawable);
		System.out.println("Init Drawable");
	}
	
	@Override
	public void initInput(){
		super.initInput();
		
		addMouseButtonMapping("Jump", MouseInput.BUTTON_LEFT,MouseInput.BUTTON_RIGHT);
	}
	
	@Override
	public void update(GLAutoDrawable drawable){
		super.update(drawable);
		inputManager.update();
		plane.translate(new Vector3f(x,0,0));
		x+=0.0001;
		
		mrT.getAnimation().setParameter("roll", time);
		mrT.getAnimation().setParameter("LightPosition", new float[]{1.0f,1.0f,1.0f});
		time+=0.01;
	}
	
	@Override
	protected void updateActionListener(String name, boolean pressed){
		super.updateActionListener(name, pressed);
		if(name=="Jump" && pressed){
			System.out.println("ROFL");
		}
	}
	
	@Override
	protected void updateAnalogListener(String name, float value){
		super.updateAnalogListener(name, value);
		if(name=="MouseLeft"){
			System.out.println("Left! value: "+value);
		}
		if(name=="MouseRight"){
			System.out.println("Right! value: "+value);
		}
		if(name=="MouseUp"){
			System.out.println("Up! value: "+value);
		}
		if(name=="MouseDown"){
			System.out.println("Down! value: "+value);
		}
	}
	
}
